package com.dmzc.stage3.ThreadLocalMap;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class Test1 {
    private static ThreadLocal<Integer>threadLocal=new ThreadLocal<>();
    private final int threadLocalHashCode = nextHashCode();
    private static AtomicInteger nextHashCode =
            new AtomicInteger();
    private static final int HASH_INCREMENT = 0x61c88647;

    private static int nextHashCode() {
        return nextHashCode.getAndAdd(HASH_INCREMENT);
    }

    public static void main(String[] args) throws InterruptedException {
        threadLocal.set(1);
//        TimeUnit.SECONDS.sleep(5);
        Thread t=new Thread(){
            @Override
            public void run() {
                threadLocal.set(12);
                System.out.println(threadLocal.get());
            }
        };
        t.start();
        for (int i = 0; i < 5; i++) {
            System.out.println(nextHashCode());
        }

    }
}
